package com.mikufufu.blog.model.vo.api;

import com.mikufufu.blog.common.enums.SexType;
import com.mikufufu.blog.model.entity.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
public class UserVO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 用户id
     */
    @ApiModelProperty(value = "用户id")
    private Integer id;

    /**
     * 用户名
     */
    @ApiModelProperty(value = "用户名")
    private String username;

    /**
     * 用户昵称
     */
    @ApiModelProperty(value = "用户昵称")
    private String nickname;

    /**
     * 用户头像
     */
    @ApiModelProperty(value = "用户头像")
    private String avatar;

    /**
     * 角色
     */
    @ApiModelProperty(value = "角色")
    private String role;

    /**
     * 邮箱
     */
    @ApiModelProperty(value = "邮箱")
    private String email;

    /**
     * 电话号码
     */
    @ApiModelProperty(value = "电话号码")
    private String phone;

    /**
     * 性别(0.保密，1.男，2女)
     */
    @ApiModelProperty(value = "性别(0.保密，1.男，2女)")
    private String gender;

    /**
     * 文章数
     */
    @ApiModelProperty(value = "文章数")
    private Integer articleNum;

    /**
     * 点赞数
     */
    @ApiModelProperty(value = "点赞数")
    private Integer likeNum;

    /**
     * 收藏数
     */
    @ApiModelProperty(value = "收藏数")
    private Integer collectNum;

    /**
     * 评论数
     */
    @ApiModelProperty(value = "评论数")
    private Integer commentNum;

    private UserVO(User user) {
        this.id = user.getId();
        this.username = user.getUsername();
        this.nickname = user.getNickname();
        this.email = user.getEmail();
        this.phone = user.getPhoneNumber();
        this.avatar = user.getAvatar();
        this.gender = SexType.getName(user.getGender());
    }

    /**
     * 转换
     * @param user {@link User}
     * @return {@link UserVO}
     */
    public static UserVO convert(User user) {
        return new UserVO(user);
    }
}
